package nb.util;

import java.util.Map;

/**
 * Bounds for a variable, [min, max).
 * Initially both set to NaN.
 */
public final class Bounds {
    public double min = Double.NaN;
    public double max = Double.NaN;

    @Override
    public String toString() {
        return "[min = " + min + ", max = " + max + "]";
    }

    /**
     * Get bounds for realVarIndex from boundsMap, creating new Bounds object and adding it
     * if it is not found.
     * @param boundsMap
     * @param realVarIndex
     * @return bounds for realVarIndex
     */
    public static Bounds getBounds(Map<Integer, Bounds> boundsMap, int realVarIndex) {
        Bounds bounds = boundsMap.get(realVarIndex);
        if (bounds == null) {
            bounds = new Bounds();
            boundsMap.put(realVarIndex, bounds);
        }
        return bounds;
    }
}